//
//  AddMedicine.h
//  Pocket Doctor alpha version
//
//  Created by Sherif, Yin, Taylor, Jacob, Anna, Mike on 11-10-25.
//  Copyright (c) 2011 __Sytjam__. All rights reserved.
//
//Class Description: Adding all the medication requirements and times.
//                   Creates notifications on save.
//
//Known Bugs: none.
//missing feature : remind you when to refill.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@class MedicineView;

@interface AddMedicine : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate>{

    //Database related variable
    int editID;    
    
    //Class View
    MedicineView *mv;
    
    //Point to the appDelegate for its SQLite database pointer.
    AppDelegate * aD;
    sqlite3 *dinDB;
    
    UILabel *initialName;
    UILabel *initialRefill;
    UILabel *initialInstructions;
    UILabel *initialAmountLeft;
    UILabel *initialtypeID;
    UILabel *initialAmount;
    
    UITextField *medName;
    UITextField *amount;
    UITextField *amountLeft;
    UITextField *instructions;
    
    UIButton *viewTime;
    UIButton *dosageType;
    
    UISwitch *refill;

    UINavigationBar *addOrModifyMed;
    UIBarButtonItem *Cancel;
    UIBarButtonItem *save;
    
    UINavigationBar *viewMedicine;
    UIBarButtonItem *back;
    UIBarButtonItem *edit;
    
    UINavigationBar *addTimes;
    UIBarButtonItem *doAddTime;
    UIBarButtonItem *cancelAddTime;
    
    UINavigationBar *editNavigationBar;
    UIBarButtonItem *editOrDone;
    
    UINavigationBar *dosageNavigator;
    UIBarButtonItem *doneDosageNavigator;    
    
    UILabel *name;
    UILabel *type;
    UILabel *amountLabel;
    UILabel *amountLeftLabel;
    UILabel *typeID;
    UILabel *refillable;
    
    UITableView *timetable;
    
    //Dosage Pickers
    NSArray *pickerArray;
    UIPickerView *dosagePicker;
    UIButton *donePicker;
    
    //Add Time Picker
    UIDatePicker *addAnotherTime;
    UIButton *doneTime;
    NSMutableArray *timeList;
    UINavigationBar *header3;
    UINavigationItem *header3title;
    UIBarButtonItem *addTime;
    UIBarButtonItem *doneTimeTable;
    
    UIImageView *saving;
    UIActivityIndicatorView *pleaseWait;
    UILabel *saveInProgress;
}

@property (nonatomic) int editID;

@property (retain, nonatomic) MedicineView *mv;
@property (retain, nonatomic) AppDelegate *aD;

@property(retain,nonatomic) IBOutlet UILabel *initialName;
@property(retain,nonatomic) IBOutlet UILabel *initialRefill;
@property(retain,nonatomic) IBOutlet UILabel *initialInstructions;
@property(retain,nonatomic) IBOutlet UILabel *initialAmountLeft;
@property(retain,nonatomic) IBOutlet UILabel *initialtypeID;
@property(retain,nonatomic) IBOutlet UILabel *initialAmount;

//Dosage Picker
@property(retain,nonatomic) NSArray *pickerArray;
@property(retain,nonatomic) IBOutlet UIPickerView *dosagePicker;
@property(retain,nonatomic) IBOutlet UIButton *donePicker;

//Date Picker
@property (retain, nonatomic) IBOutlet UIDatePicker *addAnotherTime;
@property(retain,nonatomic) IBOutlet UIButton *doneTime;
@property(retain,nonatomic) NSMutableArray *timeList;

//interface

@property(retain,nonatomic) IBOutlet UITextField *medName;
@property(retain,nonatomic) IBOutlet UITextField *amount;
@property(retain,nonatomic) IBOutlet UITextField *amountLeft;
@property(retain,nonatomic) IBOutlet UITextField *instructions;

@property(retain,nonatomic) IBOutlet UIButton *viewTime;
@property(retain,nonatomic) IBOutlet UIButton *dosageType;

@property(retain,nonatomic) IBOutlet UISwitch *refill;

@property(retain,nonatomic) IBOutlet UINavigationBar *header3;
@property(retain,nonatomic) IBOutlet UINavigationItem *header3title;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *doneTimeTable;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *addTime;

@property(retain,nonatomic) IBOutlet UINavigationBar *addOrModifyMed;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *Cancel;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *save;

@property(retain,nonatomic) IBOutlet UINavigationBar *viewMedicine;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *back;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *edit;

@property(retain,nonatomic) IBOutlet UINavigationBar *addTimes;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *doAddTime;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *cancelAddTime;

@property(retain,nonatomic) IBOutlet UINavigationBar *editNavigationBar;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *editOrDone;

@property(retain,nonatomic) IBOutlet UINavigationBar *dosageNavigator;
@property(retain,nonatomic) IBOutlet UIBarButtonItem *doneDosageNavigator;    

@property(retain,nonatomic) IBOutlet UILabel *name;
@property(retain,nonatomic) IBOutlet UILabel *type;
@property(retain,nonatomic) IBOutlet UILabel *amountLabel;
@property(retain,nonatomic) IBOutlet UILabel *amountLeftLabel;
@property(retain,nonatomic) IBOutlet UILabel *typeID;
@property(retain,nonatomic) IBOutlet UILabel *refillable;

@property(retain,nonatomic) IBOutlet UITableView *timetable;

@property(retain,nonatomic) IBOutlet UIImageView *saving;
@property(retain,nonatomic) IBOutlet UIActivityIndicatorView *pleaseWait;
@property(retain,nonatomic) IBOutlet UILabel *saveInProgress;



//Interface Functions
- (IBAction)Cancel:(id)sender;
- (IBAction)Save:(id)sender; //UPDATE or INSERT into Medicine
- (IBAction)Edit:(id)sender;
- (IBAction)Back:(id)sender;
- (IBAction)doneKeyboard:(id)sender;
- (IBAction)tapBackground:(id)sender;

- (void)animateTextField: (UITextField *) textField up: (BOOL)up;
- (IBAction)textFieldDidEndEditing:(UITextField *)textField;
- (IBAction)textFieldDidBeginEditing:(UITextField *)textField;

- (IBAction)textFieldDidBeginEditingName:(UITextField *)textField;
- (IBAction)textFieldDidEndEditingName:(UITextField *)textField;
- (void) animateTextFieldName: (UITextField *) textField up: (BOOL) up;

//Medication Functions
- (IBAction)AddTime:(id)sender;
- (IBAction)ViewTime:(id)sender;
- (IBAction)DosageType:(id)sender;

//Picker Functions
- (IBAction)DoneDosagePicker:(id)sender;
- (IBAction)DoneAddingAnotherTime:(id)sender;
- (IBAction)CancelAddingAnotherTime:(id)sender;
- (IBAction)DoneViewTime:(id)sender;

//Helper Functions that load medicine data into the interface.
- (void)loadMedicineByID;
- (IBAction)InsertDate:(id)sender;
- (BOOL)CheckInputs;
- (BOOL)isNumeric:(NSString *) s;
- (void)dinNumber;
- (void)CreateLocalNotification:(NSDate *)medicineTime;

//support functions
- (void)UnlockFields:(BOOL)enable;
- (BOOL)WillEdit;

@end
